package com.iwomy.secureplat.platform.transmission;

import com.iwomy.secureplat.platform.transmission.parse.ParseData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Collections;
import java.util.List;


public class MainPrl {
	private static final Logger logger = LoggerFactory.getLogger(MainPrl.class);
//	private static DataReceiveConfig cfg=DataReceiveConfig.getInstance();

	public static void main(String[] args) {
		// TODO 自动生成的方法存根

		List<DrcProInfo> list = Collections.emptyList();
//		List<DrcProInfo> list=cfg.listDrcPros;
		for (DrcProInfo drcProInfo : list) {
			try {
				logger.info("初始化程序：" + drcProInfo.getParseDataName());
//		    	CommTool.printInfo("初始化程序："+drcProInfo.getParseDataName());

//		    	CommTool.printInfo( drcProInfo.getJarPath());

//		    	URL url=new URL("file:"+ drcProInfo.getJarPath());
				URL url = null;
				URLClassLoader myClassLoader = new URLClassLoader(new URL[]{url},
						Thread.currentThread().getContextClassLoader());
				Class myClass = null;
				ParseData parseData = null;
				try {
					myClass = myClassLoader.loadClass(drcProInfo.getJarClassFullName());
					parseData = (ParseData) myClass.newInstance();
					parseData.setDrcProInfo(drcProInfo);

				} catch (ClassNotFoundException e) {
					e.printStackTrace();
					continue;
				} catch (InstantiationException e) {
					e.printStackTrace();
					continue;
				} catch (IllegalAccessException e) {
					e.printStackTrace();
					continue;
				}
				DataRecvServer server = new DataRecvServer(drcProInfo.getPort(),
						drcProInfo.getParseDataName(), parseData);
				try {
					server.start();
				} catch (Exception e) {
					// TODO 自动生成的 catch 块
					e.printStackTrace();
				}
				myClassLoader.close();
			} catch (IOException e) {
				logger.error(e.getMessage());
				e.printStackTrace();
			}
		}

	}

}